using UnityEngine;
using UnityEngine.EventSystems;

public class TooltipTrigger : MonoBehaviour, IPointerEnterHandler, IPointerExitHandler, ISelectHandler, IDeselectHandler, IPointerClickHandler, IEventSystemHandler
{
	public ItemCollector Item;

	public string Type = "inventory";

	private Vector3 pointerPosition;

	public void Start()
	{
	}

	public void OnPointerClick(PointerEventData eventData)
	{
		Vector2 position = eventData.position;
		float x = position.x;
		Vector2 position2 = eventData.position;
		pointerPosition = new Vector3(x, position2.y - 18f, 0f);
		Select(pointerPosition);
	}

	public void OnPointerEnter(PointerEventData eventData)
	{
		GUIItemCollector component = GetComponent<GUIItemCollector>();
		if ((bool)component)
		{
			Item = component.Item;
		}
		if ((bool)TooltipDetails.Instance)
		{
			StartCoroutine(TooltipDetails.Instance.OnHover(eventData, Item));
		}
	}

	public void OnSelect(BaseEventData eventData)
	{
	}

	public void OnPointerExit(PointerEventData eventData)
	{
		if ((bool)TooltipDetails.Instance)
		{
			TooltipDetails.Instance.hover = false;
		}
	}

	public void OnDeselect(BaseEventData eventData)
	{
	}

	private void Select(Vector3 position)
	{
		GUIItemCollector component = GetComponent<GUIItemCollector>();
		if ((bool)component)
		{
			Item = component.Item;
		}
		if (Item != null)
		{
			if ((bool)TooltipUsing.Instance)
			{
				TooltipUsing.Instance.ShowTooltip(Item, position, Type);
			}
			else
			{
				UnityEngine.Debug.Log(TooltipUsing.Instance);
			}
		}
		if ((bool)TooltipDetails.Instance)
		{
			TooltipDetails.Instance.HideTooltip();
		}
	}
}
